package com.wwl.ailangchain4j.controller;

import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.community.model.dashscope.WanxImageModel;
import dev.langchain4j.data.image.Image;
import dev.langchain4j.model.ollama.OllamaChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.output.Response;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wwl
 * 日期  2025/10/17 14:51
 * 版本 1.0
 * 描述 :
 */
@RestController
public class OpenAiController {

    @Autowired
    private OpenAiChatModel openAiChatModel;
    @Autowired
    private OllamaChatModel ollamaChatModel;
    @Autowired
    private QwenChatModel qwenChatModel;
    @Resource
    private WanxImageModel wanxImageModel;
    @GetMapping("/chat")
    public String chat(@RequestParam(value = "question", defaultValue = "你好") String question) {
        return openAiChatModel.chat(question);
    }
    @GetMapping("/ollama/chat")
    public String ollamaChat(@RequestParam(value = "question", defaultValue = "你好") String question) {
        return ollamaChatModel.chat(question);
    }
    @GetMapping("/qwen/chat")
    public String qwenChat(@RequestParam(value = "question", defaultValue = "你好") String question) {
        return qwenChatModel.chat(question);
    }
    @GetMapping("/wanx/image")
    public String wanxImage(@RequestParam(value = "question") String question) {
        if (question.isEmpty()){
            return "请输入你要生成图片的内容。";
        }
        Response<Image> response =wanxImageModel.generate(question);
        return response.content().url().toString();
    }
}
